﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using WebManager;
using Maticsoft.DBUtility;//请先添加引用

namespace BaoJian.WebManager.eshop
{
    public partial class ecolumnlist : System.Web.UI.Page
    {
        private string ColumnID = null;
        protected void Page_Load(object sender, EventArgs e)
        {
            ColumnID = HttpContext.Current.Request.QueryString["oid"];
            if (!Page.IsPostBack)
            {
                BindData();
            }
        }

        protected void Doc_Click(object sender, EventArgs e)
        {
            string url = URLUtility.UrlBase + "/WebManager/eshop/ecolumnnew.aspx?ColumnID=" + ColumnID;
            Page.Response.Redirect(url);
        }

        //protected void Edit_Click(object sender, EventArgs e)
        //{

        //}

        protected void Delete_Click(object sender, EventArgs e)
        {
            string sel = HttpContext.Current.Request.Form["selectCB"];
            if (sel == null)
            {
                return;
            }
            string[] sels = sel.Split(',');

            string sql = "DELETE FROM [EColumn] WHERE [EColumnID]='{0}' AND [PID]='{1}'";
            
            for (int i = 0; i < sels.Length; i++)
            {
                string sql1 = string.Format(sql, ColumnID, sels[i]);
                DbHelperSQL.ExecuteSql(sql1);
            }
            BindData();
        }
      
        void BindData()
        {
           string sql = "PID in (SELECT PID FROM [EColumn] WHERE [EColumnID]='{0}') order by SID desc";
           LYQ.BLL.EProduct bll = new LYQ.BLL.EProduct();
           sql = String.Format(sql,ColumnID);
           using(DataSet ds = bll.GetList(sql))
            {
                GridView1.DataSource = ds.Tables[0].DefaultView;
                GridView1.DataBind();
            }
        }   

        protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
        {
            GridView1.PageIndex = e.NewPageIndex;
            BindData();
        }
    }
}
